package com.patmen.android.PhoneCard;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

/** This class defines the activity that is created when the already created profile 
 * is clicked. 
 * 
 * @author Arvind Menon
 * @author Amruta Patwardhan
 */

public class ProfileEditor extends Activity {

	/** Object of classes */
	CountryCode CC1 = new CountryCode();
	
	private Spinner spinner_outgoing_calls_to;
	private boolean saveProfile = true;
	private int mProfileIndex;
	private String COUNTRY_CODES[];
	
	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		final Intent intent = getIntent();
		mProfileIndex = intent.getIntExtra("ProfileIndex", 0);
		
		setContentView(R.layout.editprofile);
		
		spinner_outgoing_calls_to = (Spinner) findViewById(R.id.spinner_outgoing_calls_to);
		
		// Create the spinner to allow the user to choose a country and code
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
                android.R.layout.simple_spinner_item);
        
        COUNTRY_CODES = CC1.getCountryList();
        
        for (int i = 0; i < COUNTRY_CODES.length; i++)
			adapter.add(COUNTRY_CODES[i]);
        
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        
        spinner_outgoing_calls_to.setAdapter(adapter);
	}

	// Function to call when save is hit
	private void onSaveButton() {
		saveProfile = true;
		// Return with status OK
		setResult(RESULT_OK);
		finish();
	}

	// Function to call when dont save is hit
	private void onDontSaveButton() {
		saveProfile = false;
		// Return with status CANCELLED
		setResult(RESULT_CANCELED);
		finish();
	}

	// Function that is called when the activity is
	// paused. This will happen with a finish() call
	// or if the back button is pressed.
	@Override
	protected void onPause() {
		super.onPause();

		if (!saveProfile) // We dont need to save the profile
			return;

		// Save the profile to the preferences before exiting

		// Set the status to OK
		setResult(RESULT_OK);
	}

}
